package com.lzh.farmersshop.controller;

import com.lzh.farmersshop.entity.Admininfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 后台管理跳转地址
 *
 * @author ShiChaojie
 * @date 2024/1/4 15:44
 */
@Slf4j
@Controller
@RequestMapping("admin")
public class ToAdminController {

    /**
     * 跳转到后台主页
     *
     * @return
     */
    @RequestMapping("index")
    public ModelAndView tIndex() {
        return new ModelAndView("admin/index");
    }

    /**
     * 跳转到登录页面
     *
     * @return
     */
    @RequestMapping("login")
    public ModelAndView toLogin() {
        return new ModelAndView("admin/login");
    }

    /**
     * 跳转到欢迎页面
     *
     * @return
     */
    @RequestMapping("welcome")
    public ModelAndView toWelcome() {
        return new ModelAndView("admin/welcome");
    }

    /**
     * 跳转到个人信息页面
     *
     * @return
     */
    @RequestMapping("persion")
    public ModelAndView toPersion(HttpServletRequest request) {
        // 获取Session对象
        HttpSession session = request.getSession();
        //获取用户信息
        Admininfo user = (Admininfo) session.getAttribute("admininfo");
        ModelAndView mv = new ModelAndView("admin/persion");

        mv.addObject("user", user);
        Date birthday = user.getBirthday();

        // 转换为 LocalDateTime 类型
        LocalDateTime localDateTime = new java.sql.Timestamp(
                birthday.getTime()).toLocalDateTime();

        // 创建 DateTimeFormatter 对象并设定转换格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // 格式化日期
        String formattedDate = localDateTime.format(formatter);
        mv.addObject("birthday", formattedDate);
        return mv;
    }

    /**
     * 跳转到管理员列表页面
     *
     * @return
     */
    @RequestMapping("adminList")
    public ModelAndView toAdminList() {
        return new ModelAndView("admin/user/adminList");
    }

    /**
     * 跳转到添加用户页面
     */
    @RequestMapping("addAdmin")
    public ModelAndView toAddAdmin() {
        return new ModelAndView("admin/user/addAdmin");
    }

    /**
     * 跳转到修改用户页面
     */
    @RequestMapping("updateAdmin")
    public ModelAndView toUpdateAdmin() {
        return new ModelAndView("admin/user/updateAdmin");
    }

    /**
     * 跳转到会员用户列表页面
     *
     * @return
     */
    @RequestMapping("userList")
    public ModelAndView toUserList() {
        return new ModelAndView("admin/userinfo/userList");
    }

    /**
     * 跳转到会员用户查看收货地址页面
     *
     * @return
     */
    @RequestMapping("userArdessList")
    public ModelAndView toUserArdessList() {
        return new ModelAndView("admin/userinfo/userArdessList");
    }

    /**
     * 跳转到商品分类列表页面
     *
     * @return
     */
    @RequestMapping("goodsTypeList")
    public ModelAndView toGoodsTypeList() {
        return new ModelAndView("admin/goodstype/goodsTypeList");
    }

    /**
     * 跳转到添加商品分类页面
     *
     * @return
     */
    @RequestMapping("addGoodsType")
    public ModelAndView toAddGoodsType() {
        return new ModelAndView("admin/goodstype/addGoodsType");
    }

    /**
     * 跳转到修改商品分类页面
     *
     * @return
     */
    @RequestMapping("updateGoodsType")
    public ModelAndView toUpdateGoodsType() {
        return new ModelAndView("admin/goodstype/updateGoodsType");
    }

    /**
     * 跳转到商品列表页面
     *
     * @return
     */
    @RequestMapping("goodsList")
    public ModelAndView toGoodsList() {
        return new ModelAndView("admin/goods/goodsList");
    }

    /**
     * 跳转到添加商品列表页面
     *
     * @return
     */
    @RequestMapping("addGoods")
    public ModelAndView toAddGoods() {
        return new ModelAndView("admin/goods/addGoods");
    }

    /**
     * 跳转到修改商品列表页面
     *
     * @return
     */
    @RequestMapping("updateGoods")
    public ModelAndView toUpdateGoods() {
        return new ModelAndView("admin/goods/updateGoods");
    }

    /**
     * 跳转到查看商品图列表页面
     *
     * @return
     */
    @RequestMapping("goodsImgList")
    public ModelAndView toGoodsImgList() {
        return new ModelAndView("admin/goodsimg/goodsImgList");
    }

    /**
     * 跳转到添加商品图列表页面
     *
     * @return
     */
    @RequestMapping("addGoodsImg")
    public ModelAndView toAddGoodsImg(Integer goodsid) {
        ModelAndView mv = new ModelAndView("admin/goodsimg/addGoodsImg");
        mv.addObject("goodsid", goodsid);
        return mv;
    }

    /**
     * 跳转到修改商品图列表页面
     *
     * @return
     */
    @RequestMapping("updateGoodsImg")
    public ModelAndView toUpdateGoodsImg() {
        return new ModelAndView("admin/goodsimg/updateGoodsImg");
    }

    /**
     * 跳转到轮播图列表页面
     *
     * @return
     */
    @RequestMapping("bannerList")
    public ModelAndView toBannerList() {
        return new ModelAndView("admin/banner/bannerList");
    }

    /**
     * 跳转到添加轮播图列表页面
     *
     * @return
     */
    @RequestMapping("addBanner")
    public ModelAndView toAddBanner() {
        return new ModelAndView("admin/banner/addBanner");
    }

    /**
     * 跳转到修改轮播图列表页面
     *
     * @return
     */
    @RequestMapping("updateBanner")
    public ModelAndView toUpdateBanner() {
        return new ModelAndView("admin/banner/updateBanner");
    }

    /**
     * 跳转到商品评价列表页面
     *
     */
    @RequestMapping("goodsEvaluationList")
    public ModelAndView toGoodsEvaluationList() {
        return new ModelAndView("admin/goodsEvaluation/goodsEvaluationList");
    }

    /**
     * 跳转到回复商品评价页面
     *
     */
    @RequestMapping("hfEvaluation")
    public ModelAndView toHfEvaluation() {
        return new ModelAndView("admin/goodsEvaluation/hfEvaluation");
    }

    /**
     * 跳转到订单列表页面
     */
    @RequestMapping("orderList")
    public ModelAndView toOrderList() {
        return new ModelAndView("admin/order/orderList");
    }

    /**
     * 跳转到订单详情列表页面
     */
    @RequestMapping("orderDetailsList")
    public ModelAndView toOrderDetailsList() {
        return new ModelAndView("admin/order/orderDetailsList");
    }

}
